import requests

# url = f'http://localhost:5000/pdf_translate/pdf/中文'
#
# file_path = '/home/yzq/openai-quickstart/openai-translator/ai_translator/tests/test.pdf'
#
# files = {'file': open(file_path, 'rb')}
#
# response = requests.post(url, files=files)
#
# print(response.text)

url = 'http://localhost:5000/get_result/test_translated.pdf'

response = requests.get(url)

# 检查请求是否成功
if response.status_code == 200:
    # 获取文件名（可以从响应头中获取或者根据需要定义）
    file_name = response.headers['Content-Disposition'].split('=')[-1]

    # 将二进制内容写入文件
    with open(file_name, 'wb') as file:
        file.write(response.content)

    print(f"File {file_name} downloaded successfully.")
else:
    print(f"Failed to download file. Status code: {response.status_code}")